home *** CD-ROM | disk | FTP | other *** search
- Path: howland.reston.ans.net!psinntp!psinntp!psinntp!psinntp!usenet
- From: grantp@usa.pipeline.com(Pete Grant)
- Newsgroups: comp.lang.c++,
- Subject: Re: Why does this work?
- Date: 27 Mar 1996 22:46:09 GMT
- Organization: Kalevi, Inc.
- Message-ID: <4jcgfh$fs5@news1.h1.usa.pipeline.com>
- References: <DoxvnA.L0C@mail.auburn.edu>
- NNTP-Posting-Host: 38.8.60.7
- X-PipeUser: grantp
- X-PipeHub: usa.pipeline.com
- X-PipeGCOS: (Pete Grant)
- X-Newsreader: Pipeline v3.5.0
-
- On Mar 27, 1996 18:35:33 in article <Why does this work?>,
- 'greerjo@mail.auburn.edu (John M. Greer)' wrote:
-
-
- >This is probably a horribly simple question, but I was going through a
- >few books, brushing up on my iostreams, when I saw this tidbit in Jamsa's
-
- >Multimedia Trilogy (The CD-ROM by Kris Jamsa)
- >
- >#include <iostream.h>
- >#include <ctype.h>
- >
- >void main(void)
- >{
- >char letter;
- >
- >while (! cin.eof())
- >{
- >letter = cin.get();
- >letter = toupper(letter);
- >cout << letter;
- >}
- >}
- >
- >Why does this work!?!? It seems to reserve storage for only one
- >character in letter, but outputs a whole line at a time. Feel free to
- >flame my stupidity, but please satisfy my curiosity (I'm really not this
- >clueless, I promise!!)
-
- Ok, ask and ye shall receive.. Consider yourself flamed :-)
-
- Actually, the above code outputs a single character at a time.
- However, you may only see a line at a time as the characters
- are buffered until the system decides it's time to empty
- the buffer. According to the 'specs', output buffer is
- flushed when an endl or flush manipulator is 'processed',
- or when the output stream is closed. However, most systems
- flush the buffer when a newline is encountered.
-
- --
- Pete Grant
- Kalevi, Inc.
- Software Engineering & development
-